<!DOCTYPE html>
<html lang="en" style="height: 100%">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="../vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="../vendors/jquery/dist/jquery.min.js"></script>
    <script src="../vendors/bootstrap/dist/js/bootstrap.js"></script>
    <script src="../vendors/bootstrap/extend/DT_bootstrap.min.js"></script>
    <script src="../vendors/bootstrap/extend/Modalz_Bootstrap.min.js"></script>

</head>
<body style="height: 100%">
<div style="margin:15px auto; "> <div style="width:1080px; margin:15px auto;">
    <button id="btnadd" type="button" class="btn btn-success">新&nbsp;&nbsp;&nbsp;增</button>
    <div id="sample_3">
        <table style="width: inherit;" class="table"><thead><tr><th style="width:15%;overflow:hidden;"><div style="white-space: nowrap;overflow: hidden;">名称</div></th><th style="width:15%;overflow:hidden;"><div style="white-space: nowrap;overflow: hidden;">资源版本</div></th><th style="width:25%;overflow:hidden;"><div style="white-space: nowrap;overflow: hidden;">uid</div></th><th style="width:10%;overflow:hidden;"><div style="white-space: nowrap;overflow: hidden;">状态</div></th><th style="width:20%;overflow:hidden;"><div style="white-space: nowrap;overflow: hidden;">创建时间</div></th><th style="width:15%;overflow:hidden;"><div style="white-space: nowrap;overflow: hidden;">操作</div></th></tr></thead>
            <tbody id="rowdata">

            </tbody></table>
    </div></div></div>
<script type="text/javascript">
    $(function () {
        dataload();
        $("#btnadd").click(function () {
            showinfo();
        })
    })
    function dataload() {
        $("#rowdata").empty();
        var storage = window.localStorage;
        var a1 = storage.kuberenvir
        a1 =JSON.parse(a1);
        var  str="";
        for(var i=0;i<a1.Data.length;i++)
        {
            var str1="<button class=\"btn btn-primary btn-xs\" onclick=\"editnamespace('" + a1.Data[i].name + "')\" title=\"编辑\" >编辑</button>&nbsp;&nbsp;";
             str1+="<button class=\"btn btn-primary btn-xs\" onclick=\"deletenamespace('" + a1.Data[i].name + "','"+a1.Data[i].uid+"')\" title=\"删除\" >删除</button>&nbsp;&nbsp;";
            str+="<tr><td>"+a1.Data[i].name+"</td><td>"+a1.Data[i].resourceVersion+"</td><td>"+a1.Data[i].uid+"</td><td>"+a1.Data[i].status+"</td><td>"+a1.Data[i].creationTimestamp+"</td><td>"+str1+"</td></tr>";
        }
        $("#rowdata").append(str);
         /*    var config = {
            showCheckbox: false,
            queryParams: {},
            url: "/api/kubernamespace/getall",
            columns: [
                { field: 'name', title: '名称', width: 15 },
                { field: 'resourceVersion', title: '资源版本', width: 15 },
                { field: 'uid', title: 'uid', width: 25},
                { field: 'status', title: '状态', width: 10 },
                { field: 'creationTimestamp', title: '创建时间', width: 20 },
                {field:'',title:'操作',width:15,formatter: function (rowData) {
                     var str="<button class=\"btn btn-primary btn-xs\" onclick=\"editnamespace('" + rowData.name + "')\" title=\"编辑\" >编辑</button>&nbsp;&nbsp;";
                    return str+"<button class=\"btn btn-primary btn-xs\" onclick=\"deletenamespace('" + rowData.name + "','"+rowData.uid+"')\" title=\"删除\" >删除</button>&nbsp;&nbsp;";

                }}

            ]
        }
        $("#sample_3").dataGrid(config);*/

    }
    function editnamespace(name)
    {
        $.modalz("/src/app/views/kuber_namespaceadd.html?name="+name, "编辑", 250, 120);
    }
    function deletenamespace(name,uid) {
        var storage = window.localStorage;
        var a1 = storage.kuberenvir;
        a1 = JSON.parse(a1);
        for (var i = 0; i < a1.Data.length; i++) {
            if (a1.Data[i].name == name) {
                a1.Data.splice(i,1);
            }
        }
        storage.kuberenvir = JSON.stringify(a1);
        timedMsg()
        loadmeun()

        }
    function timedMsg()
    {
        setTimeout( "dataload()",200);
    }
    function loadmeun()
    {
        window.parent.window.timedMsg();
    }
    function showinfo()
    {
        $.modalz("/src/app/views/kuber_namespaceadd.html", "新增", 250, 120);

    }
</script>
</body>
</html>